package cn.hebutrun.oulabot.common.util;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.experimental.UtilityClass;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@UtilityClass
public class ResponseUtil {

  public void out(HttpServletResponse httpResponse, Object apiResponse) {
    ObjectMapper mapper = new ObjectMapper();
    httpResponse.setStatus(HttpStatus.OK.value());
    httpResponse.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
    try {
      mapper.writeValue(httpResponse.getWriter(), apiResponse);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
